var distributeArgs={};
distributeArgs.defaultUrl = '/commoditylog/list.json';
distributeArgs.url = distributeArgs.defaultUrl;
distributeArgs.distribute='-1';
distributeArgs.commodity='0';

Ext.define('channel.commodity.CommodityLogList',{
	extend : 'Ext.panel.Panel',
	alias: 'widget.commodityloglist',
	layout : 'border',
	initComponent : function(){
		
		this.west = Ext.create('Ext.tree.Panel',{
			margins : '2 2 2 2',
			region : 'west',
			title: '菜单',
		    width: 200,
		    tools : [
		    	{name:'refresh',type:'refresh',qtip:'刷新模块树',disabled :false,handler:function(){
		    		this.center.store.removeAll();
		    	},scope:this}
		    ],
		    store: westTreeStore,
		    listeners : {
		    	'itemclick':function(view, record, htme, index, e){
		    		var distribute = record.get('distribute');
		    		if(distribute != -99){
			    		distributeArgs.distribute = distribute;
			    		this.centerStore.load();
		    		}
		    	},scope:this
		    },
		    viewConfig: {
		        plugins: {
	                ptype: 'treeviewdragdrop',
                	appendOnly: true
	            }
		    }
		});
		
		this.centerStore = Ext.create('Ext.data.Store', {
  	        fields: ['id', 'distribute','commodity','add','onshelf','offshelf','updatename',
  	                 'updateprice','updatestock','updatecovers','updatedescription','executetime',
  	                 'success','errorMessage'],
  	        pageSize: 25,      
  	        proxy: {
  	            type: 'ajax',
  	            actionMethods : 'post',           
  	            url : distributeArgs.url, 
  	            timeout : 1000*60*3,           
  	            extraParams :distributeArgs,
  		        reader: {
  		            type: 'json',
  		            root: 'channelResult.result',
  		            totalProperty: 'channelResult.totalCount'
  		        }
  	        },
  	        autoLoad: false,
  	        listeners : {
  	        	'load':function(){
  	        		this.down('#refreshBtn').setDisabled(false);
  	        	},
  	        	'beforeload':function(thiz,options){
  	        		this.down('#refreshBtn').setDisabled(true);
  	        	},scope:this
  	        }
  	    });
	    
		this.center = Ext.create('Ext.grid.Panel',{
			margins : '2 2 2 0',
			region : 'center',
			loadMask: true,
			columnLines: true,
		    store : this.centerStore,
		    viewConfig: {
		    	stripeRows: true,
      	        trackOver: true,
      	        emptyText : '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
		    },    
		    columns: [
		            	{xtype: 'rownumberer',width: 80, sortable: true,align:'center'},
		              	{header: '编号',  dataIndex: 'id',width:80},
		                {header: '渠道号',  dataIndex: 'distribute',width:50},
		              	{header: '商品编号',  dataIndex: 'commodity',width:120},
		              	{header: '新增',  dataIndex: 'add',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '上架',  dataIndex: 'onshelf',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '下架',  dataIndex: 'offshelf',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '名称',  dataIndex: 'updatename',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '价格',  dataIndex: 'updateprice',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '库存',  dataIndex: 'updatestock',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '图片',  dataIndex: 'updatecovers',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '描述',  dataIndex: 'updatedescription',width:50,renderer:function(v){return v==1 ? '√':'-';}},
		              	{header: '生成时间',dataIndex: 'executetime',width:140,renderer:function(v){
		              		return Ext.util.Format.date(new Date(parseInt(v)),'Y-m-d H:m:s');
		              	}},
		              	{header: '结果',  dataIndex: 'success',width:50,renderer:function(v,m){
		              			return v==1 ? '成功':'<div style="color:#a31515;">失败<div>';
		              		}
		              	},
		              	{header: '错误信息',dataIndex: 'errorMessage',width:200},
		              ],
		    tbar : [
	      	    	{text:'刷 新',iconCls:'refresh',scope:this,handler:function(){
	      	    		this.center.store.load();
	      	    	},itemId:'refreshBtn'},'-',
	      	    	{text:'查 看',iconCls:'edit',disabled:true,itemId:'detailBtn',handler:this.showDetailWin,scope:this},'-',
	      	    	{text:'查 询',iconCls:'refresh',scope:this,handler:this.showSearchWin,itemId:'searchBtn'}
	      	    ],
	      	selModel : Ext.create('Ext.selection.CheckboxModel', {
			        listeners: {
			            selectionchange: function(sm, selections) {
			                var n = selections.length||0;
							this.center.down('#detailBtn').setDisabled(n!=1);
			            },scope:this
			        }
			    }),
	      	  dockedItems:[{
	 	          xtype: 'pagingtoolbar',
	 	          store: this.centerStore,
	 	          dock: 'bottom',
	 	          displayMsg: 'Displaying CommodityLog {0} - {1} of {2}',
	 	          emptyMsg: "No CommodityLog to display",
	 	          displayInfo: true,
	 	          items:[
	 	                '-', {
	 	                text: 'Show Fail',
	 	                pressed: false,
	 	                enableToggle: true,
	 	                toggleHandler: function(btn, pressed) {
							Ext.Msg.alert('提示',':)');
	 	                }
	 	            }]
	 	     }],
			    listeners : {
			    	'afterrender' : function(gp){
			    		gp.view.on('itemdblclick',function(){
			    			var m = gp.getSelectionModel().getSelection();
			    			if(m.length==1){
			    				this.showDetailWin();
		    				}
			    		},this);
			    	},scope:this
			    }
		});
		this.items = [this.center,this.west];
		this.callParent();
	},
	showSearchWin :function(){
		if(!this.commodityLogWin){
			this.commodityLogWin = Ext.create('channel.commodity.CommodityLogWin',{title:'查 询',fcmp :this});
		}
		this.commodityLogWin.show();
	},
	showDetailWin :function(){
		if(!this.detailLogWin){
			this.detailLogWin = Ext.create('channel.commodity.CommodityLogDetailWin',{title:'查看详情',fcmp :this});
		}
		this.detailLogWin.show();
	}
});